<template>
  <div>
    <h1>字典管理</h1>

    <div>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="dictId" label="字典ID" />
        <el-table-column prop="dictName" label="字典名称" />
        <el-table-column prop="dictValue" label="字典值" />
        <el-table-column prop="dictType" label="字典类型" />
        <el-table-column label="操作">
          <el-button type="primary">详情</el-button>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div style="margin-top: 20px">
      <div class="demo-pagination-block" style="width: 800px; margin: 0 auto">
        <el-pagination
          v-model:current-page="searchForm.pageNum"
          v-model:page-size="searchForm.pageSize"
          :page-sizes="[2, 4, 6, 8]"
          :background="true"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { getDictListAll } from "@/api/api";
import { useRouter } from "vue-router";
import { ElMenu, ElMessage } from "element-plus";

const router = useRouter();
const tableData = ref([]);
const total = ref(0);
const dialogFormVisible = ref(false);
const formLabelWidth = "140px";
const searchForm = ref({
  pageNum: 1,
  pageSize: 10,
});

//分页回调
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  searchForm.value.pageSize = val;
  loadList();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  searchForm.value.pageNum = val;
  loadList();
};
const loadList = () => {
  getDictListAll(searchForm.value).then((res) => {
    if (res.data.code == 200) {
      tableData.value = res.data.data.records;
      total.value = res.data.data.total;
    }
  });
};
onMounted(() => {
  loadList();
});
</script>

<style scoped></style>
